package com.weigj.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;

public class CarType extends Model<CarType> {
	
	public static final CarType carTypeDao=new CarType();
	
	/**
	 * 查询部门下的车型 以及价格
	 * @param deptId 部门Id fenId 分公司Id
	 * @return
	 */
	public List<CarType> queryCarTypeByDeptId(Long deptId,Long fenId){
		String sql="select a.*,f.fcbp_baseprice from App_TopCarModel a inner join FenComBasePrice f on a.tcm_id=f.fcbp_tcmid  where a.enable=1 and a.tcm_id in(select comtcm.ct_tcmid from Com_Topcarmodel comtcm where 1=1 and comtcm.ct_fencomid=? and comtcm.ct_deptid=?) and f.fcbp_fencomid=? order by a.tcm_wholename desc";
		return carTypeDao.find(sql, fenId,deptId,fenId);
	}
	
	/**
	 * 查询车辆的其他价格信息
	 * @param carTypeId 车型Id
	 * @param fenId 分公司ID
	 * @param memberId 会员级别Id
	 * @return
	 */
	public Record queryOtherPrice(Long carTypeId,Long fenId,Long memberId){
		String sql="select d.* from Assistdata d where d.enable=1 and d.ad_topmodelid=? and d.ad_fencomid=? and d.ad_memberid=?";
		return Db.findFirst(sql,carTypeId,fenId,memberId);
	}
	
	/**
	 * 根据会员级别查询会员级别信息
	 * @param memnberType 会员级别 普通会员 金卡会员
	 * @return
	 */
	public Record queryMember(String memnberType){
		String sql="select a.* from APP_MEMBERCLASS a where a.enable=1 and a.clasname=?";
		return Db.findFirst(sql,memnberType);
	}
	/**
	 * 总公司下的限行规则
	 * @param seccode 星期几 1 2 3 4 5
	 * @param incid 总公司Id
	 * @return
	 */
	public Record queryLimit(String seccode,Long incid ){
		String sql="select t.* from app_sortcodesec t where t.type='限行规则' and t.incid=? and t.seccode=?";
		System.out.println(sql+""+incid+""+seccode);
		return Db.findFirst(sql,incid,seccode);
	}
	/**
	 * 获取所以的城市
	 * @return
	 */
	public List<Record> queryAllCity(){
		String sql="select c.* from CITY c where c.c_name in(select cityname from APP_CARINCINFO where inclevel=1 group by cityname)";
		return Db.find(sql);
	}
	public Record queryWzMoney(Long fenId){
		String sql="select b.* from breakruleprice b where b.brp_fencomid=? ";
		return Db.findFirst(sql,fenId);
	}
}
